<?php
require_once './interfaces/ISchemaElement.php';
require_once './interfaces/ISchemaWriter.php';
require_once './interfaces/ISchemaReader.php';
require_once './schema/SchemaException.php';
require_once './config/Group.php';
require_once './config/Datasource.php';

require_once './schema/Schema.php';
require_once './schema/ResolvedMismatch.php';
require_once './schema/Table.php';
require_once './schema/Field.php';
require_once './schema/Index.php';
require_once './schema/ForeignKey.php';

require_once './config/ConfigReader.php';
require_once './schema/SchemaReader.php';

require_once './schema/AbstractSynchonizer.php';
require_once './schema/BaseDomainClassGenerator.php';
require_once './schema/synchronizers/MysqlSynchronizer.php';
require_once './schema/AbstractMismatch.php';
require_once './schema/SchemaMismatch.php';
require_once './schema/DatasourceMismatch.php';
require_once './schema/SchemaWriter.php';



$testFile = "./tests/resources/test-source-file.xml";

$dbConfFile = "./tests/resources/test-configuration.xml";


$schemaReader = new SchemaReader();
$schema = $schemaReader->readSchemaFromFile($testFile);


$reader = new ConfigReader();
$result = $reader->readConfigFromFile($dbConfFile);
$ds = $result[0]->datasources[0];
$ds->connect(); 



$synchro = new MysqlSynchronizer();

print "<pre>";

/*
$table = new Table();
$table->table = "dupa";
$field = new Field();
$field->name = "W_dupie";
$field->type = "INTEGER";
$table->fields[] = $field;

$field = new Field();
$field->name = "W_dupie2";
$field->type = "DOUBLE";
$table->fields[] = $field;

$schema->tables[] = $table;
*/

$m = $synchro->getSchemaMismatches($ds, $schema);
foreach($m as $mismatch){
	print $mismatch->toString()."\n";
}

//$synchro->synchronize( $ds, $schema ); 


$generator = new BaseDomainClassGenerator();
$dir = "./cache/";
$generator->targetDir = $dir;
$generator->generate($schema);

foreach($schema->tables as $table){
  print "<h1>".$table->getTableName()."</h2>\n";
  foreach($table->getFields()  as $field){
    print "<li>".$field->getName()." {$field->getSize()}</li>";
  }
  
}


return;

$testFileTarget = "./tests/resources/test-target-file.xml";

$schema = new Schema();

$synchro->datasourceToSchema( $ds, $schema );

$writer = new SchemaWriter();
$writer->writeSchemaToFile($schema, $testFileTarget);


